import json
from datetime import datetime

from django.forms.models import model_to_dict
from django.http import JsonResponse
from django.views.decorators.csrf import csrf_exempt

from lianxi20250918.models import student


# Create your views here.
@csrf_exempt
def add_student(request):
    data=json.loads(request.body)
    if data['name']=='' or data['age']=='' or data==['gender']:
        return JsonResponse(
            {
                'msg':'参数必填'
            }
        )
    a=student.objects.create(
        name=data['name'],
        age=data['age'],
        gender=data['gender'],
        description=data['description'],
        deadline=datetime.now()
    )
    return JsonResponse(
        {
            'msg':'添加成功',
            'item': model_to_dict(a)
        }
    )
